import { Controller, Get, Post, Body, Request, UploadedFile, } from '@nestjs/common';
import { LoginService } from './login.service';
import { Public } from 'src/common/JWT/public.decorator';
// import { BusinessException } from 'src/common/exceptions/business.exception';//业务异常处理
import { ConfigService } from '@nestjs/config'
import { ApiTags } from '@nestjs/swagger';
import * as multer from 'multer';
import * as svgCaptcha from 'svg-captcha'

@ApiTags("公共接口")
@Controller('login')
export class LoginController {
    constructor(private readonly loginService: LoginService, private readonly configService: ConfigService) { }
    @Get('add')
    addUser() {
        return this.loginService.addUser();
    }
    @Public()
    @Post()
    login(@Body() data) {
        return this.loginService.toLogin(data);
    }
    @Get('findAll')
    findAll() {
        return this.loginService.getUser();
    }
    @Public()
    @Get('code')
    getCode() {
        return this.loginService.getCode();
    }

    @Public()
    @Post('upload')
    async uploadFile(@UploadedFile() file: Express.Multer.File, @Request() req: Request): Promise<any> {
        console.log(file, '----');
        const fileInfo = await this.loginService.createFile(file);
        return { file: fileInfo };
    }

}
